<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <input type="file" hidden> <button>选择</button>
  <script>
    const ipt = document.querySelector('input')
    const btn = document.querySelector('button')
    btn.addEventListener('click',()=> {
      ipt.click()
    })
    ipt.addEventListener('change',(e)=>{
      console.log('选择完文件了')
      console.log(e.target.files[0])
      // console.log(e.target.value)
      // 取到上传的文件对象后 清空value值, 保证再次选择同样的一个文件,保证change事件能触发
      e.target.value = null
    })
  </script>
</body>
</html>